/*
    This file is part of Starlight Engine.

    Starlight Engine is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    Starlight Engine is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Starlight Engine.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using StarlightEngine;

namespace StarlightEngine
{
#if ZUNE
    /// <summary>
    /// Controls input from the touch panel.
    /// </summary>
    public class TouchInput
    {

        TouchCollection touch;        

        internal TouchInput()
        {
            touch = new TouchCollection();
            touch = TouchPanel.GetState();
            Logger.Write("Multi-Touch Initialied.", 2);
        }

        public Rectangle FirstTouchRectangleTransformed
        {
            get {

                if (touch.Count > 0)
                {
                    Vector2 trans = Vector2.Transform(touch[0].Position, Matrix.Invert(Engine.CameraMatrix));
                    return new Rectangle((int)trans.X, (int)trans.Y, 20, 20);
                }
                else
                {                    
                    return new Rectangle(0, 0, 0, 0);
                }
                
            }
        }

        /// <summary>
        /// Gets the total touches.
        /// </summary>
        /// <value>The total touches.</value>
        public int TotalTouches
        {
            get { return touch.Count; }
        }

        /// <summary>
        /// Gets the touches.
        /// </summary>
        /// <value>The touches.</value>
        public TouchLocation GetTouch(int id)
        {
            if (TotalTouches > id)
                return touch[id];
            else
                return new TouchLocation(1, TouchLocationState.Pressed, Vector2.Zero, 1f);

        }

        /// <summary>
        /// Updates the touch panel.
        /// </summary>
        /// <param name="time">The time.</param>
        public void Update(GameTime time)
        {
            touch = TouchPanel.GetState();
        }        
    }
    
#endif

}